Web     = http://bic.googlecode.com/svn/branches/tiny#
Default = eg000
Tmp     = $(HOME)/tmp
GawkDir = $(HOME)/opt/gawk
Gawk    = $(GawkDir)/bin/gawk
PGawk   = $(GawkDir)/bin/pgawk
DGawk   = $(GawkDir/bin/dgawk
Info    = $(GawkDir)/share/info/gawk.info
Lib     = ./lib
Src     = ./src
Doc     = ./doc
Etc     = ./etc

Dirs    = $(Tmp) $(Lib) $(Var) $(Src) $(Etc)

#######################################

Awks    = $(shell ls *.awk)
Srcs    = $(Src)/$(subst .awk ,.awk $(Src)/,$(Awks))
Shs     = $(Src)/$(subst .awk , $(Src)/,$(Awks))
Docs    = $(subst .awk,.html,$(Doc)/$(subst .awk ,.awk $(Doc)/,$(Awks)))
AWKPATH = "$(Src):./"

#################################
Vars    = $(Tmp)/vars.out
Run     = AWKPATH=$(AWKPATH) $(Gawk) -f demos.awk
Debug   = AWKPATH=$(AWKPATH) $(DGawk) -f demos.awk
Watch   = AWKPATH=$(AWKPATH) $(PGawk) \
              --dump-variables=$(Tmp)/vars.out \
              --profile=$(Tmp)/profile.out \
              -f demos.awk 
Demo    = $(Watch) -v Demo# 
Z       = | cat -n | tee $(Tmp)/last_$@.txt;echo "" ; \
          echo "Rogues :"; cat $(Vars)| \
          egrep  '^[abcdefghijklmnopqrstuvwxyzz0123456789_]:'|sort|cat -n 
A       = @echo "\#-- $@ -------------------";

###################################
one   : $(MAKE) $(Default)
ready : lib.awk demos.awk $(Lib)/comment.awk $(Lib)/markup.awk \
        dirs $(Gawk) $(PGawk) files
dirs  : ; @mkdir -p $(Dirs)
help  : ; info $(Info)

files : $(Docs) $(Srcs) $(Shs)  # Srcs MUST preceded SHs

$(Src)/%.awk : %.awk
	@$(Gawk) -f $(Lib)/comment.awk $< > $@
	svn -q add $@ 

$(Src)/% :  %.awk
	@echo "#!$(Gawk) -f " > $@ 
	@(echo " "; echo "# $<";) >> $@
	@(echo -n "# "; svn info | grep Revision)>> $@
	@echo "# Built by $(USER) on `date`." >> $@
	@cat $(Etc)/header.txt >> $@ 
	@cat $(Src)/$< >> $@
	@chmod +x $@ 
	svn -q add $@

$(Doc)/%.html : %.awk
	@(cat $(Etc)/header.html;  \
	$(Gawk) -f $(Lib)/markup.awk  $<; \
        cat $(Etc)/footer.html)  \
        | sed 's|~~~|$(Web)|g' | sed 's|~~=|$<|g' > $@
	svn -q add $@
	@svn -q propset svn:mime-type text/html $@

$(Gawk) : boot/gawk-3.1.84.tar.gz
	@cp $< $(Tmp)
	@cd $(Tmp); tar xzf gawk-3.1.84.tar.gz
	@cd $(Tmp)/gawk-3.1.84; ./configure --prefix=$(GawkDir)  
	@cd $(Tmp)/gawk-3.1.84; $(MAKE) ; $(MAKE) install

###################################

commit :
	svn -q add * */*
	svn commit -m stuff

update :
	svn update

profile :
	less $(Tmp)/profile.out 
